package com.jjty.dataGenerator.bg.controller;

import com.jjty.dataGenerator.bg.service.impl.LoginService;
import com.jjty.dataGenerator.common.ApiResult;
import com.jjty.dataGenerator.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: huangyulong
 * @createTime: 2023-08-28 10:41
 * @Description:
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService service;

    /**
     * 登录
     * @return
     */
    @RequestMapping("/login")
    public ApiResult login(String username, String password){

        try{
            String token = service.login(username,password);
            return ApiResult.doSuccess("登录成功",token);
        }catch (ServiceException e){
            return ApiResult.doFailure(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResult.doFailure("系统异常，及时联系管理员处理"+e.getMessage());
        }

    }

}
